package cn.yqn.controller;

import cn.yqn.domain.User;
import cn.yqn.downgrade.DowngradeUtil;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope // 刷新配置
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getById/{id}")
    @SentinelResource(value="user-server-getById", blockHandler = "degradationMethod", blockHandlerClass = DowngradeUtil.class)
    public User getById(@PathVariable("id") Long id){
        return new User(id, "源码时代", "我在源码时代学习Java!");
    }
}
